package com.ebupt.migu.music.autoTri.Controller;

import com.ebupt.migu.music.autoTri.Service.VipBlockService;
import com.ebupt.migu.music.common.auth.IDAuthUtils;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.Map;

/**
 * @description: 自动触发-会员红包策略分组管理
 * @author: liuyangyang@ebupt.com
 * @date: 2021/6/23 14:18
 */
@Slf4j
@RestController
@RequestMapping("/vip/block")
public class VipBlockController {

    @Autowired
    private IDAuthUtils idAuthUtils;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private VipBlockService vipBlockService;

    /**
     * 创建自动触发-会员红包策略分组
     *
     * @return
     */
    @PostMapping("/add")
    public ResultObject add() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        return vipBlockService.add(params);
    }

    /**
     * 查询自动触发-会员红包策略分组
     *
     * @return
     */
    @PostMapping("/query")
    public ResultObject query() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        return vipBlockService.query(params);
    }

    /**
     * rowkey|scene_id|block_id|accept_valid_time|use_valid_type|use_valid_time|card_value|buy_limit|uid_create_time
     * @param args
     */
    public static void main(String[] args) throws IOException {
        String perUID = "9f2ed96f-9227-417c-a44f-";
        String tacID = "10001";
        String sceneID = String.valueOf((int) Math.random() * 3 + 1);
        String blockID = String.valueOf((int) Math.random() * 3 + 1);
        String acceptValidTime = "20220701120000";
        String useValidType = "1";
        String useValidTime = "20220701120000";
        String cardValue = "5";
        String buyLimit = "12";
        String uidCreateTime = "20210706120000";
        File file = new File("D:\\vip_packet_detail");
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
        for (int i = 100001; i <= 110000; i++){
            StringBuffer str = new StringBuffer();
            str.append(perUID + i + "_" + tacID + "_" + i);
            str.append("|" + Math.random() * 3 + 1);
            str.append("|" + Math.random() * 3 + 1);
            str.append("|" + acceptValidTime);
            str.append("|" + useValidType);
            str.append("|" + useValidTime);
            str.append("|" + cardValue);
            str.append("|" + buyLimit);
            str.append("|" + uidCreateTime);
            bufferedWriter.write(String.valueOf(str));
            bufferedWriter.newLine();
        }
    }
}
